package com.ytfs.utils;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 * @Classname Jpautil
 * @Description TODO(Jpa实体类管理工厂)
 * @Date 2020/4/28 23:38
 * @Created by ytfs
 */
public class JpaUtil {

    //线程安全的
    private static final EntityManagerFactory FACTORY;

    static {

        /*这里的实体类工厂的persistenceUnitName是配置文件中
         <persistence-unit name="myJpa" transaction-type="RESOURCE_LOCAL">
         */
        FACTORY = Persistence.createEntityManagerFactory("myJpa");

    }

    /**
     * 返回实体类管理对象
     * @return
     */
    public static EntityManager getEM(){
        return FACTORY.createEntityManager();
    }
}
